package amst.system;

public class MWTPScheduler implements Scheduler {

	private int[] ddps = new int[3];
	
	public int findNextQueue(SystemQueue queues[], double actualTime) {
		Packet packet1 = null, packet2 = null;
		int returnIndex = 0;
		double vx = Integer.MAX_VALUE;
		for (int i = 0; i < queues.length; i++) {
			packet1 = queues[i].checkPacket();
			if(packet1 != null) {
				double vi = 0;
				System.out.print("i=" + i + " ");
				for (int j = 0; j < queues.length; j++) {
					packet2 = queues[j].checkPacket();
					if(packet2 != null) {
						double v = 0;
						System.out.print("j=" + j+ ", delay: " + packet2.getDelay(actualTime) + ": ");
						if(i == j) {
							v = packet2.getDelay(actualTime) / ddps[j];
						} else {
							v = (packet2.getDelay(actualTime) + packet1.getServiceTime()) / ddps[j];
						}
						System.out.print("" + v + " ");
						if(v > vi) vi = v;
					}
				}
				System.out.println(" MAX=" + vi);
				if(vx > vi) {
					vx = vi;
					returnIndex = i;
				}
			}
		}
		 
		return returnIndex;
	}

	public void setDDP(int[] ddps) {
		this.ddps[0] = ddps[0];  
		this.ddps[1] = ddps[1];
		this.ddps[2] = ddps[2];
	}

}
